﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;

namespace HZ.Supervise.Web.Hospital
{
    public partial class HospitalPurchasePlanByZero : BasePage
    {
        
 
        IExecuteContext iec = HZ.Supervise.BLLFactory.ExecuteContext();

        public HospitalPurchasePlanByZero()
        {
            this.ModuleNo = Module.医院统计分析.ToString();
            this.PageOperateType = OperateType.医院预采购计划填报情况.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                int year = System.DateTime.Now.Year;
                int month = System.DateTime.Now.Month + 1;
                if (month == 12)
                {
                    year += 1;
                }
                txtPurchaseTime.Text = year + "-" + month + "-01";
                BindData();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        { 
            BindData();

        }

        /// <summary>
        /// 绑定数据 
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanListByZero(vs, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;

            this.gvwInfo.PageSize = AspNetPager1.PageSize;
            this.gvwInfo.DataSource = dt;
            this.gvwInfo.DataBind();



        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
        



        /// <summary>
        /// 导出 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanListByZero(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery();  
            vs.HospitalName = txtHospitalName.Text.Trim();
            vs.AreaID = HZ.Supervise.Web.Function.GetAreaIDBySQL(AreaControl1.SelectedAreaID);
            if (!string.IsNullOrEmpty(txtPurchaseTime.Text.Trim()))
            {
                vs.PurChaseTime = Convert.ToDateTime(txtPurchaseTime.Text.Trim());
            }

            switch (ddlHosType.SelectedValue)
            {
                case "0":
                    break;
                case "1":
                    vs.Levels = "'3','4','5','6'";
                    break;
                case "2":
                    vs.IsCountry = "'1','2','3','4'";
                    break;
                case "3":
                    vs.IsCountry = "'2'";
                    break;
                case "4":
                    vs.IsCountry = "'1'";
                    break;
                default:
                    break;
            }

            vs.IsGovernment = ddlIsGov.SelectedValue; 
            vs.SortFields = "HospitalID ";
            return vs;
        }


        
    }

}

